﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AutoplanetaTaskManager.Daos;
using AutoplanetaTaskManager.Daos.EntityFramework;
using AutoplanetaTaskManager.Models;

namespace AutoplanetaTaskManager.Views.Admin
{
    public partial class RemoveEmployeeForm : Form
    {
        private readonly IUserDao _userDao = new UserDao();
        private readonly IRoleDao _roleDao = new RoleDao();
        private User _user;

        public RemoveEmployeeForm(int userId)
        {
            InitializeComponent();
            _user = _userDao.Get(userId);
            if (_roleDao.Get(_user.RoleId).Name != "USER")
                _user = null;
        }

        private void RemoveEmployeeForm_Load(object sender, EventArgs e)
        {
            if (_user != null)
            {
                firstNameTextBox.Text = _user.FirstName;
                lastNameTextBox.Text = _user.LastName;
                userNameTextBox.Text = _user.UserName;
                passwordTextBox.Text = _user.Password;
            }
            else
            {
                MessageBox.Show("Операция не доступна", "Ошибка!");
                Dispose();
            }
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            Dispose();
        }

        private void removeButton_Click(object sender, EventArgs e)
        {
            if (_user!=null)
                _userDao.Remove(_user.Id);
            Dispose();
        }
    }
}
